<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE HTML>

<html xmlns="http://www.w3.org/1999/xhtml">

	<head>

		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

		<title><?php echo C('WEB_TITLE');?></title>

		<link rel="stylesheet" type="text/css" href="/Public/css/common.css"/>

		<link rel="stylesheet" type="text/css" href="/Public/js/layui/css/layui.css" media="all"/>

		<link rel="stylesheet" href="/Public/js/datepicker/datepicker.css"/>

		<link rel="stylesheet" type="text/css" href="/Public/crm/css/index.css"/>

		<link rel="stylesheet" type="text/css" href="/Public/crm/css/style.css"/>

		<link rel="stylesheet" href="<?php echo C('PC_ICON_HTTP');?>">

		<script type="text/javascript" >

			const moduleName = "<?php echo (MODULE_NAME); ?>";

		</script>

        <link rel="stylesheet" href="/Public/js/viewer/css/viewer.min.css">
		
		<link rel="stylesheet" type="text/css" href="/Public/js/select2/select2.css" media="all"/>

		<script type="text/javascript" src="/Public/js/jquery-1.9.1.min.js"></script>
		
		<script type="text/javascript" src="/Public/js/jquery-ui.min.js"></script>

		<script type="text/javascript" src="/Public/js/cookie/jquery.cookie.js"></script>

		<script type="text/javascript" src="/Public/js/lang/<?php echo (getStrToLower(cookie('think_language'))); ?>.js"></script>

		<script type="text/javascript" src="/Public/js/colorpicker.js"></script>

		<script type="text/javascript" src="/Public/js/layer/layer.js"></script>

		<script type="text/javascript" src="/Public/js/layui/layui.js"></script>

        <script type="text/javascript" src="/Public/js/feeldesk.js"></script>

        <script type="text/javascript" src="/Public/crm/js/index.js"></script>

        <script type="text/javascript" src="/Public/js/jquery.nicescroll.js"></script>

		<script type="text/javascript" src="/Public/js/clipboard.min.js"></script>

		<script type="text/javascript" src="/Public/js/select2/select2.min.js"></script>

		<script type="text/javascript" src="/Public/js/select2/jquery.core.js"></script>

	</head>

<body>

<script type="text/javascript" src="/Public/js/datepicker/datepicker.all.js"></script>

<script type="text/javascript" src="/Public/js/datepicker/moment.min.js"></script>

<script type="text/javascript" src="/Public/js/datepicker/datepicker.en.js"></script>

    <div class="fd-right-main">

        

    <div class="list-main">

		<div class="layui-tab">

            <ul class="layui-tab-title">

                <li class="layui-this"><?php echo L('CLUE_CUSTOM_FIELD_SETTINGS');?></li>

            </ul>

        </div>

        <div class="list-header clearfix">

            <div class="header-left">

                <?php echo FEELCRM('DefineForm/create',['type'=>encrypt('clue','DEFINEFORM')],L('NEW_FORM'),'item-deleteBtn','','iconfont icon-xinzeng');?>

            </div>

            <div class="header-right">

                <form action="<?php echo ($controllerAndAction); ?>" method="get" class="fr">

                    <div class="compact-search">

                        <i class="iconfont icon-search"></i>

                        <input type="text" name="keyword" value="<?php echo ($keyword); ?>" placeholder="<?php echo L('NAME/TYPE');?>"/>

                        <a href="javascript:" class="searchBtn"><?php echo L('SEARCH');?></a>

                    </div>

                </form>

            </div>

        </div>

        <div class="item-list feelcrm-list">

            <table class="layui-table" lay-skin="line" id='sortable'>

                <thead>

                    <tr>

                        <th><?php echo L('FORM_NAME');?></th><th><?php echo L('FORM_TYPE');?></th><th><?php echo L('IS_NOT_REQUIRED');?></th><th><?php echo L('WHETHER_TO_PREVENT_WEIGHT');?></th><th><?php echo L('LIST_DISPLAY');?></th>
                        <th><?php echo L('IS_ENABLE');?></th><th><?php echo L('SORT');?></th><th><?php echo L('OPERATION');?></th>

                    </tr>

                </thead>

                <tbody>

                    <?php if(empty($clueform)): ?><tr class="nodata center">

                            <td colspan="8">

                                <p><i class="iconfont icon-nothing fts20"></i></p>

                                <p><?php echo L('NO_DATA');?></p>

                            </td>

                        </tr>

                    <?php else: ?>

                        <?php if(is_array($clueform)): $i = 0; $__LIST__ = $clueform;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><tr class='cursor-move' sort="<?php echo ($vo["orderby"]); ?>">

                                <td><?php echo ($vo["form_description"]); ?></td>

                                <td><?php echo ($vo["form_type"]); ?></td>

                                <td><?php if(($vo["is_required"]) == "0"): ?><span class="red1"><?php echo L('YES');?></span><?php else: ?><span class="green1"><?php echo L('NO');?></span><?php endif; ?></td>

								<td><?php if(($vo["is_unique"]) == "1"): ?><span class="red1"><?php echo L('YES');?></span><?php else: ?><span class="green1"><?php echo L('NO');?></span><?php endif; ?></td>

								<td><?php if(($vo["show_list"]) == "1"): ?><span class="red1"><?php echo L('YES');?></span><?php else: ?><span class="green1"><?php echo L('NO');?></span><?php endif; ?></td>

                                <td>

                                    <?php if(($vo["closed"]) == "1"): ?><span class="open-status disable"><?php echo L('DISABLE');?></span>

                                    <?php else: ?>

                                        <span class="open-status enable"><?php echo L('ENABLE');?></span><?php endif; ?>

                                </td>

                                <td><span><?php echo ($vo["orderby"]); ?></span></td>

                                <td class="listOperate">

                                    <i class="iconfont icon-dian"></i>

                                    <div class="operate hidden">

                                        <?php echo FEELCRM('DefineForm/edit',['id'=>encrypt($vo['form_id'],'DEFINEFORM'),'type'=>encrypt('clue','DEFINEFORM')],l('EDITOR'));?>

                                       <?php if(($vo["is_default"]) != "1"): echo FEELCRM('DefineForm/delete',['id'=>encrypt($vo['form_id'],'DEFINEFORM'),'type'=>encrypt('clue','DEFINEFORM')],l('DELETE'),'','async'); endif; ?>

                                    </div>

                                </td>

                            </tr><?php endforeach; endif; else: echo "" ;endif; endif; ?>

                </tbody>

            </table>

            <?php if(!empty($page)): ?><div class="right-list-page clearfix"><div class="feeldesk-page"><?php echo ($page); ?></div></div><?php endif; ?>

        </div>

    </div>

    <script type="text/javascript">

        var fixHelper = function(e, ui)
        {
            ui.children().each(function()
            {
                $(this).width($(this).width());  //在拖动时，拖动行的cell（单元格）宽度会发生改变。在这里做了处理就没问题了
            });

            return ui;
        };

        $(function()
        {
            var sortable = $("#sortable");

            var formIds = [];//受影响的表单ID

            var selectSort,selectSx,placeSort,placeSx,temp,flag;

            sortable.find('tbody').sortable(
            {
                cursor: "move",
                helper: fixHelper,                  //调用fixHelper
                axis:"y",
                start:function(e, ui)
                {
                    ui.helper.css({"background":"#fff"});  //拖动时的行，要用ui.helper
                    return ui;
                },
                sort:function(e, ui)
                {
                    formIds = [];

                    selectSort = ui.item.attr("sort"); //当前元素的顺序

                    placeSort = $(this).find('tr').filter('.ui-sortable-placeholder').next('tr').attr('sort');//新位置下的下一个元素的排序

                    placeSx = parseInt(placeSort);

                    selectSx = parseInt(selectSort);

//                    说明是 向上移动
                    if(selectSx > placeSx)
                    {
                        temp = placeSort;

                        placeSx = selectSort;//最大

                        selectSx = temp;//最小

                        flag = false;
                    }
                    else
                    {
//                        向下移动
                        placeSort = $(this).find('tr').filter('.ui-sortable-placeholder').prev('tr').attr('sort');

                        placeSx = parseInt(placeSort);

                        flag = true;
                    }
                },
                stop:function(e, ui)
                {
                    var temp = "";

                    var definForm = JSON.parse('<?php echo ($clueFormJson); ?>');

                    $.each(definForm,function(k,v)
                    {
                        var sort = parseInt(v.orderby);

                        if(sort >= selectSx && sort <= placeSx)
                        {
                            if(sort == parseInt(selectSort))
                            {
                                if(flag)
                                {
                                    temp = v.form_id;
                                }
                                else
                                {
                                    formIds.splice(0,0,v.form_id);
                                }
                            }
                            else
                            {
                                formIds.push(v.form_id);
                            }
                        }
                    });

                    if(flag)
                    {
                        formIds.splice(placeSx-selectSx,0,temp);
                    }

                    $.ajax(
                    {
                        url:"<?php echo U('AjaxRequest/updateDefinFormSort');?>",
                        type:'POST',
                        async: false,
                        data:{'ids':formIds, selectSx:selectSx, placeSx:placeSx},
                        datatype:'json',
                        success:function()
                        {
                            window.location.reload();
                        },
                        error:function()
                        {
                           layer.msg("<?php echo L('SAVE_SORT_EXCEPTION');?>");
                        }
                    });

                    return ui;
                }
            });

            sortable.disableSelection();
        });

    </script>



    </div>

    <script type="text/javascript">

        layer.ready(function()
        {
            layer.photos({
                photos: '.textareaImg',
                shift: 5,
                shade: [0.8, 'rgba(0,0,0,.8)']
            });

        })

    </script>

    <script>

        //客户端
        /*if ( navigator.userAgent.toLowerCase().indexOf('electron/') > -1)
        {
            top.setIframe(document);
        }*/
    </script>

    </body>

</html>